package org.gwt.grin.rebind.features;

import java.util.Formatter;

import org.gwt.grin.client.features.FixedImage;
import org.gwt.grin.rebind.SEFeature;
import org.gwt.grin.rebind.ShowBuilder;

public class SEFixedImage extends SEFeature {

	private final int x;
	private final int y;
	private final String imageResource;

	public SEFixedImage(String name, int x, int y, String imageResource) {
		super(name);
		this.x = x;
		this.y = y;
		this.imageResource = imageResource;
	}

	@Override
	public String write(ShowBuilder builder) {
		String cn = getClassName();
		Formatter formatter = new Formatter();
		formatter.format("new %s(\"%s\", %d, %d, %s)", cn, name, x, y,
				makeImageResource(imageResource));
		return formatter.toString();
	}

	private String makeImageResource(String imageResource) {
		return "getClientBundle()." + imageResource + "()";
	}

	@Override
	protected String getClassName() {
		return FixedImage.class.getName();
	}

}
